package com.sise.wangzhan.client;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * @Classname TestFeignClient
 * @Description TODO
 * @Date 2020/5/6 22:21
 * @Created by wangzhan
 */
public class TestFeignClient {
    public static void main(String[] args) throws InterruptedException {

        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        Logger logger = loggerContext.getLogger("root");
        logger.setLevel(Level.toLevel("INFO"));

        // 创建默认HttpClient
        final CloseableHttpClient httpClient = HttpClients.createDefault();
        // 调用多次服务并输出结果
        for (int i = 0; i < 6; i++) {
            // 建立线程访问接口
            Thread t = new Thread() {
                @Override
                public void run(){
                    try {
                        String url = "http://localhost:9000/feign/hello";
                        // 调用Get方法请求服务
                        HttpGet httpGet = new HttpGet(url);
                        // 获取响应
                        HttpResponse response = httpClient.execute(httpGet);
                        // 根据响应解析字符串
                        System.out.println(response.getEntity());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            };
            t.start();
        }
        // 等待完成
        Thread.sleep(15000);
    }
}
